<%@ page language="java" contentType="text/javascript; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import='java.sql.*' %>
<%@page import="java.util.ArrayList"%>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="net.sf.json.JSONSerializer"%>
<%@page import="net.sf.json.JSONArray"%>

<%
	response.setHeader("Access-Control-Allow-Origin", "*");
	response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
	request.setCharacterEncoding("UTF-8");
	String num = request.getParameter("num");
	String title = request.getParameter("title");
	String content = request.getParameter("content");
	//String title = new String(request.getParameter("title").getBytes("8859_1"), "utf-8");
	//String content = new String(request.getParameter("content").getBytes("8859_1"), "utf-8");
	String continent = request.getParameter("continent");
	String nation = request.getParameter("nation");
	//content = content.replace("\n","<br>"); // 줄바꿈 값을 <br>로 
	//content = content.replace("\u0020","&nbsp;"); // 띄어쓰기를 &nbsp;로 
	
	String date = new java.text.SimpleDateFormat("yyyy-MM-dd").format(new java.util.Date());
	String time = new java.text.SimpleDateFormat("HH:mm:ss").format(new java.util.Date()); // kk로 해야 12가 더해진 시간이 나온다
	
	Connection conn = null;
	PreparedStatement pstmt = null;
	
	try{
		Class.forName("com.mysql.jdbc.Driver");
		conn = DriverManager.getConnection(
			"jdbc:mysql://localhost/itscreater", "itscreater", "campus123");
		
		String update = "update Post set Title = ?, Content = ?, Continent = ?, Nation = ?, Date = ?, Time = ? where Number = ?;";
		pstmt = conn.prepareStatement(update);
		pstmt.setString(1, title);
		pstmt.setString(2, content);
		pstmt.setString(3, continent);
		pstmt.setString(4, nation);
		pstmt.setString(5, date);
		pstmt.setString(6, time);
		pstmt.setString(7, num);
		pstmt.executeUpdate();
		
		JSONObject jo = new JSONObject();
		jo.put("success", "true");
		out.print(jo);	
		
	}
	
	finally{
		try{
			pstmt.close();
		}
		catch (Exception ignored){
		}
		try{
			conn.close();
		}
		catch (Exception ignored){
		}
	}
%>